package com.freshcity.manager.support
{
	import com.freshcity.lib.util.ObjectPool;
	import com.greensock.TimelineMax;
	import com.pblabs.debug.Logger;
	
	import flash.display.Sprite;

	public class MsgRollTipsImpl extends Sprite
	{
		private var _msgs:Vector.<String>;

		private var currentStartTime:int;
		private var isStart:Boolean=false;
		private var _periodCount:int=1;
		private var isFinish:Boolean=true;
		private var _timeLine:TimelineMax;

		public function MsgRollTipsImpl()
		{
			_msgs=new Vector.<String>();
			_timeLine=new TimelineMax({repeat: -1});
			_timeLine.addCallback(onTick, 0.1);
		}

		public function onTick():void
		{
			var loc1:String=null;
			var loc2:RollTipsItem=null;
			//Logger.debug(this,"onTick",String(this._msgs.length));
			if (this._msgs.length > 0 && this.isFinish)
			{
				loc1=this._msgs.shift();
				loc2=ObjectPool.getObject(RollTipsItem);
				this.isFinish=false;
				loc2.updateData(loc1, this.onInEnd);
				this.showRollTips(loc2);
			}
			else if(this._msgs.length <= 0)
			{
				_timeLine.stop();
				this.isStart=false;
			}
		}

		private function onInEnd(arg1:RollTipsItem):void
		{
			isFinish=true;
			if (arg1.parent)
			{
				arg1.parent.removeChild(arg1);
			}
			arg1.dispose();
			ObjectPool.disposeObject(arg1, RollTipsItem);
		}

		private function showRollTips(arg1:RollTipsItem):void
		{
			x = stage.stageWidth / 2 - arg1.width / 2;
			y = stage.stageHeight / 2 + 80;
			this.addChild(arg1);
		}

		private function hideRollTips():void
		{
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
		}

		/**
		 * 提示信息
		 */
		public function showMsg(text:String):void
		{
			_msgs.push(text);
			if (!isStart)
			{
				_timeLine.play();
				isStart=true;
			}
		}

	}
}
